import Vue from 'vue'
import Router from 'vue-router'
import routers from './routers'
import vuex_store from '../store/index.js'
import storage from '../storage/storage.js'

Vue.use(Router)

const router = new Router({
    history: true,
    saveScrollPosition: true,
    suppressTransitionError: true,
    routes: routers
})

router.beforeEach(({ meta, path }, from, next) => {
    var { authType } = meta

    // if (authType) {
    //     console.log("vuex: " + vuex_store.state.authType);
    //     if (authType != vuex_store.state.authType) {
    //         return next({ path: '/login' })
    //     }
    // }
    if (authType) {
        var json = JSON.parse(storage.getUser());
        if (json) {
            if (json.authType) {
                if (authType = json.authType) {
                    return next();
                }
            }
        }
        return next({ path: '/login' })
    }
    next();
})


// 输出router
export default router;
